package com.yxq.mdt.app.modules.personal.presenter;

import com.yxq.mdt.app.base.BasePresenter;
import com.yxq.mdt.app.modules.personal.bean.RealNameResultBean;
import com.yxq.mdt.app.modules.personal.model.RealNameModel;
import com.yxq.mdt.app.net.ApiModel;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.http.Body;

public class RealNamePresenter extends BasePresenter<IRealNameContract.View, RealNameModel> implements IRealNameContract.Presenter {

    public RealNamePresenter(IRealNameContract.View rootView, RealNameModel model) {
        super(rootView, model);
    }

    @Override
    public void saveRealName(String code, String resultCode, String identityCardName, String identityCardNo) {
        mBaseModel.saveRealName(code, resultCode, identityCardName, identityCardNo, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String data) {
                mRootView.onLoadSuccess(data);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadFailed(errMsg);
            }
        });
    }

    public void saveOpenChat(String data) {

        final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

        RequestBody body = RequestBody.create(JSON, data);

        mBaseModel.saveOpenChat(body, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String data) {
                mRootView.onLoadSuccess(data);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadFailed(errMsg);
            }
        });
    }

    public void saveCard(String identityCardName, String identityCardNo, String identityCardFront, String identityCardBack) {
        mBaseModel.saveCard(identityCardName, identityCardNo, identityCardFront, identityCardBack, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String data) {
                mRootView.onLoadSuccess(data);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadFailed(errMsg);
            }
        });
    }

    public void getCardNoAndName() {
        mBaseModel.getCardNoAndName(new ApiModel.CommonCallback<RealNameResultBean>() {
            @Override
            public void onSuccess(RealNameResultBean data) {
                mRootView.onLoadRealNameSuccess(data);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadRealNameFailed(errMsg);
            }
        });
    }
}
